<template>
	<view class="Menu">
		<!-- 导航条 :style="{ height: $wanlshop.wanlsys().height + 'px' }"-->
		<view class="cu-custom">
			<view class="cu-bar fixed bg-bgcolor" :style="{height: $wanlshop.wanlsys().height + 'px',}">
				<view class="action">
					<text class="wlIcon-fanhui1" style="margin-left: 0" @tap="$wanlshop.back(1)"></text>
				</view>
				<view class="content" :style="{ top: $wanlshop.wanlsys().top + 'px' }">
					<!-- 转账 -->
					{{$t('otcTransfer.page.title')}}
				</view>
				<view class="action">
					<text class="wlIcon-gengduo"></text>
				</view>
			</view>
		</view>
		<view style="position: fixed;height: auto;  width: auto; top: 0; left: 0; bottom: 0; right: 0;"
			:style="{top: $wanlshop.wanlsys().height + 'px',}">
			<view class="transferBox">
				<view class="assets">
					<view class="assetsT">
						<view class="title">{{$t('otcTransfer.page.head.title')}}<!-- 资产 --></view>
						<view class="pick" @click="typeShow(current)" :class="{'yld':current==1}">{{type}}
							<u-icon size="10" name="arrow-down-fill" style="margin-left: 16rpx;"></u-icon>
						</view>
					</view>
					<view class="assetsM">
						<view class="assetsInput">
							<u--input border='none' v-model="Inputmoney"></u--input>
						</view>
						<view class="assetsmMoney">
							<!-- 余额 -->{{$t('otcTransfer.page.head.subtitle')}}:{{money||0}}
						</view>
					</view>
				</view>
				<view class="formList">
					<h1><!-- 转出账号 -->{{$t('otcTransfer.input.transferAccount.title')}}</h1>
					<view class="list">{{mobile}}</view>
				</view>
				<view class="formList">
					<h1>转账类型</h1>
					<view style="display: flex;">
						<view class="radio text-xxl" v-for="(item,index) in typeList" :key="index"
							:class="{'active':current==item.id}" @click="dianji(item,item.id)">
							<text class="wlIcon-xuanze-danxuan wanl-orange"></text>
							<text class="wlIcon-xuanze wanl-gray-light"></text>
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="formList">
					<h1><!-- 接受账号 -->{{$t('otcTransfer.input.acceptAccount.title')}}</h1>
					<view class="list">
						<u--input border='none' v-model="in_mobile"
							:placeholder="$t('otcTransfer.input.acceptAccount.placeholder')"></u--input>
						<!-- 请输入接受账号 -->
					</view>
				</view>
				<!-- 	<view class="formList">
					<h1>支付密码</h1>
					<view class="list">
						<u-code-input v-model="pwd" :space="0" borderColor="#E6E6E6" size='53' :maxlength="6"
							:dot='true'></u-code-input>
					</view>

				</view> -->
			</view>
			<view class="uni-btn">
				<button class="uni-btn-v" @click="formSubmit1"> {{$t('otcExtract.but.submit')}} <!-- 确认 --></button>
			</view>
		</view>
		<u-picker :show="show" :columns="columns" keyName="label" @close='close' @cancel='close' @confirm='confirm'
			:closeOnClickOverlay='true'></u-picker>
		<u-popup :show="show1" mode="bottom" @close="close" :closeable='true' :closeOnClickOverlay='true' round="16rpx">
			<view class="cont">
				<view class="title">请输入支付密码</view>
				<view class="xy">
					<u-code-input v-model="pwd" :space="0" borderColor="#E6E6E6" size='58' :maxlength="6"
						:dot='true'></u-code-input>
				</view>
				<view class="btn-reset" @click="payBtn">支付</view>
			</view>
		</u-popup>
		<u-loading-icon text="支付中..." textSize="18" :show="show2" :vertical='true' loading-color='#fff'
			color="#fff"></u-loading-icon>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				money: '',
				Inputmoney: '0',
				show: false,
				show1: false,
				show2: false,
				columns: [
					[
						// {
						// 	label: 'STOK',
						// 	id: 2
						// }, 
						{
							label: 'YLD',
							id: 3
						}, {
							label: 'UT',
							id: 4
						}
					]
				],
				type: 'YLD',
				id: '3',
				mobile: '',
				in_mobile: '',
				captcha: '',
				count: 60,
				counting: false,
				typeList: [{
						id: 1,
						name: '智能交易策略终端'
					},
					{
						id: 2,
						name: '云技术服务'
					},
					{
						id: 0,
						name: '正常转账'
					}
				],
				current: 0,
				zz_type: '0',
				pwd: ''
			};
		},
		onShow() {
			this.getMoney()
			this.getxtyldpay()
			let info = uni.getStorageSync("wanlshop:user")
			if (info.mobile == '') {
				this.mobile = uni.getStorageSync("wanlshop:user").nickname
			} else {
				this.mobile = uni.getStorageSync("wanlshop:user").mobile
			}
			let payConfig = uni.getStorageSync("wanlshop:config")

		},
		methods: {
			getxtyldpay() {
				uni.request({
					url: "/index/getxtyldpay",
					data: {},
					success: (res) => {
						if (res.data.status == 1) {
							this.columns = [
								[
									// {
									// 	label: 'STOK',
									// 	id: 2
									// }, 
									{
										label: 'YLD',
										id: 3
									}, {
										label: 'UT', //'业绩',
										id: 4
									},
									// {
									// 	label: this.$t('otc.category.points'), //'$',
									// 	id: 100
									// },
								]
							]
						}
					},
				});
			},
			//获取余额
			getMoney() {
				uni.request({
					url: "/user/getMoney",
					method: 'POST',
					data: {
						type: this.id,
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.money = res.res.data.money
						}
					},
				});
			},
			// 发送手机动态码
			handleCode() {
				if (this.counting) return;
				var reg = /^1[3456789]\d{9}$/;
				if (!reg.test(this.mobile)) {
					uni.showToast({
						title: this.$t('otcTransfer.toast.auth.phone'),
						//"请输入正确的手机格式",
						icon: "none",
					});
					return;
				}
				this.getCaptcha();
			},
			// 获取验证码的接口
			getCaptcha() {
				uni.request({
					url: "/sms/send",
					method: "POST",
					data: {
						event: "mobilelogin",
						mobile: this.mobile,
					},
					success: (res) => {
						this.$wanlshop.msg(this.$t('otcTransfer.toast.getcode.success')); //"验证码发送成功"
						this.counting = true;
						const timer = setInterval(() => {
							this.count--;
							if (this.count <= 0) {
								clearInterval(timer);
								this.counting = false;
								this.count = 60; // 重置倒计时时长
							}
						}, 1000);
					},
				});
			},
			typeShow(e) {
				if (e == 1) {
					this.show = false
				} else {
					this.show = true
				}
			},
			dianji(item, e) {
				this.current = e
				if (e == 1) {
					this.type = 'YLD'
					this.id = '3'
					this.getMoney()
				}
				this.zz_type = item.id
			},
			formSubmit1() {
				this.pwd = ''
				if (this.Inputmoney == '0') {
					uni.showToast({
						title: "请输入转让的金额",
						icon: "none",
					});
					return;
				}
				if (this.in_mobile == '') {
					uni.showToast({
						title: "请输入接受账号",
						icon: "none",
					});
					return;
				}
				this.show1 = true


			},
			payBtn() {
				if (this.pwd == '' || this.pwd == null) {
					uni.showToast({
						title: '请输入支付密码',
						icon: 'none'
					})
					return
				}
				if (this.pwd.length < 6) {
					uni.showToast({
						title: '请输入正确的支付密码',
						icon: 'none'
					})
					return
				}
				uni.request({
					url: "/user/getIsPayPassword",
					method: "POST",
					success: (res) => {
						if (res.res.data.pay_password_status == "yes") {
							uni.request({
								url: "/user/reyzPayPassword",
								method: "POST",
								data: {
									paypassword: this.pwd,
								},
								success: (res) => {
									if (res.res.code == 1) {
										this.show1 = false
										this.formSubmit()
									}
								},
							});
						} else {
							this.$wanlshop.auth("/pages/newPage/paypwd");
						}
					},
				});


			},
			//转账
			formSubmit() {
				uni.request({
					url: "/user/userTransfer",
					method: 'POST',
					data: {
						in_mobile: this.in_mobile,
						// captcha: this.captcha,
						type: this.id,
						money: this.Inputmoney,
						zz_type: this.zz_type
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.$wanlshop.msg(res.res.msg);
							this.Inputmoney = '0'
							this.in_mobile = ''
							this.captcha = ''
						}
					},
				});
			},
			//选择
			confirm(val) {
				this.id = val.value[0].id.toString()
				this.type = val.value[0].label
				this.show = false
				this.getMoney()
			},
			//关闭选择
			close() {
				this.show = false
				this.show1 = false
			}
		}
	};
</script>

<style lang="scss">
	.Menu {
		background: #f8f8f8;

		.transferBox {
			padding: 0 24rpx;

			.assets {
				padding: 38rpx 30rpx 34rpx 30rpx;
				background: #fff;
				border-radius: 16rpx;
				margin-top: 24rpx;

				.assetsT {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 20rpx;

					.title {
						font-weight: 400;
						font-size: 28rpx;
						color: #333333;
						line-height: 48rpx;
					}

					.pick {
						background: #F3F3F3;
						border-radius: 4rpx;
						padding: 5rpx 6rpx 5rpx 24rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						line-height: 48rpx;
						min-width: 112rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
					}

					.yld {
						opacity: 0.5;
					}
				}

				.assetsM {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.assetsInput {
						width: 50%;

						/deep/.u-input__content__field-wrapper__field {
							font-weight: 600;
							font-size: 52rpx !important;
							color: #FF443C !important;
							line-height: 48rpx !important;
						}
					}

					.assetsmMoney {
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						line-height: 48rpx;
					}
				}
			}

			.formList {
				h1 {
					font-weight: 400;
					font-size: 24rpx;
					color: #333333;
					line-height: 48rpx;
					margin: 30rpx 0;
				}

				.list {
					background: #fff;
					border-radius: 16rpx;
					padding: 30rpx;
					position: relative;
				}

				/deep/.u-input__content {


					.u-input__content__field-wrapper__field {
						font-weight: 400;
						font-size: 28rpx !important;
						color: #333333 !important;
					}
				}

				.code {
					font-size: 28rpx;
					color: #fc5351;
					position: absolute;
					right: 30rpx;
					top: 32rpx;
				}

			}
		}

		.uni-btn-v {
			width: 702rpx;
			height: 96rpx;
			background: #eb5641;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-top: 40rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 96rpx;
			margin-bottom: 100rpx;
		}

		.text-xxl {
			font-size: 28rpx;
			color: #999999;
			margin-right: 10rpx;

			uni-text {
				margin-right: 10rpx;
			}

			.wanl-orange {
				display: none;
			}
		}

		.active {
			color: #FC5351;

			.wanl-orange {
				display: inline-block;
			}

			.wanl-gray-light {
				display: none;
			}
		}
	}

	.cont {
		.title {
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			line-height: 48rpx;
			text-align: center;
			padding: 40rpx 0;
		}

		/deep/.u-code-input {
			justify-content: center;
		}

		.xy {
			margin-bottom: 380rpx;
		}

		.btn-reset {
			width: 93%;
			height: 96rpx;
			background: #eb5641;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 96rpx;
			margin: 0 auto 40rpx;
			text-align: center;
		}
	}

	/deep/.u-loading-icon {
		background-color: rgba(0, 0, 0, 0.5);
		width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 9;

		.u-loading-icon__text {
			color: #fff !important;
		}
	}
</style>